<template>
    <view>
        <image :src="jjhsd" class="kkmseeerrt" mode="aspectFit"></image>
		
		<view class="jkkjjjsserr" @tap="ciadas(0)">
			更换车辆图片
		</view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
				jjhsd:"../../static/img/tipoisd.png",
				imageid:{},
				cardata:'',
				carid:''
			}
        },
		onLoad(options){
			this.jjhsd = options.img
			this.carid = options.carid
			console.log(options)
		},
		onNavigationBarButtonTap(){
			this.daojishise()
		},
        components: {},
        methods: {
			// ciadas(){
			// 	let th=this
			// 	uni.chooseImage({
			// 	    count: 1, //默认9
			// 	    success: function (res) {
			// 			th.jjhsd = res.tempFilePaths[0]
			// 	    }
			// 	});
			// },
			async	daojishise() {
				let params={}
				params.image=this.imageid
				let carid = this.carid
				let code=await this.get('/api/car/'+carid+'/image',params,'PUT')		
				uni.navigateBack({
					delta:1
				})
			},
			ciadas(type){
				var hbvsd = [],
				th=this
				if (type==0){ // 相册
					hbvsd= ['album']
				} else if(type == 1){ // 拍照
					hbvsd= ['camera']
				}
				let token = uni.getStorageSync('access_token')
				uni.chooseImage({
				    count: 1, //默认9
				    sourceType: ['album'], //从相册选择
				    success: function (res) {
						console.log("图片",res.tempFiles[0].name)
						// th.imgsd = res.tempFilePaths[0]						
						uni.uploadFile({
							url: 'http://kenide.youfai.cn/api/images', //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							header:{
								Accept:'application/json',
								Authorization:token
							},
							formData: {
								// 'image': res.tempFiles[0].name,
								'type':'image'
							},
							success: (uploadFileRes) => {
								let uploads=JSON.parse(uploadFileRes.data)
								console.log(uploads);
								th.jjhsd=uploads.data.path
								th.imageid=uploads.data.id
							}
						});
				    }
				});
			}
		},
        mounted() {}
    }

</script>
<style  scoped>
	.kkmseeerrt{
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
	}
	.jkkjjjsserr{
		width:308upx;
		height:100upx;
		border:2upx solid rgba(162,162,162,1);
		opacity:1;
		border-radius:12upx;
		color: #999;
		text-align: center;
		line-height: 100upx;
		position: fixed;
		left: 0;
		right: 0;
		margin:auto;
		font-size: 32upx;
		bottom: 120upx;
	}
</style>
